import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';

import 'index_controller.dart';

class IndexPage extends GetView<IndexController> {

  const IndexPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Obx(
      () => Scaffold(
          body: PageView(
              controller: controller.pageController,
              children: controller.pages,
              onPageChanged: (index) {
                controller.setCurrentIndex(index);
              },
          ),
          bottomNavigationBar: BottomNavigationBar(
            type: BottomNavigationBarType.fixed,
            selectedFontSize: 14,
            unselectedFontSize: 15,
            iconSize: 24,
            selectedItemColor: Colors.pink,
            unselectedItemColor: Colors.grey,
            items: controller.generateBottomNavList(),
            currentIndex: controller.currentIndex.value,
            onTap: _onNavItemTapped,

          )
      ),
    );
  }

  void _onNavItemTapped(int index) {
    controller.pageController.animateToPage(index, duration: const Duration(milliseconds: 200), curve: Curves.ease);
    // controller.pageController.jumpToPage(index);
  }
}
